#include "Item.h"
#include "Player.h"
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

//物品的所有基类属性
Item::Item(string name, int value, int san, int power, double movePower,
	int wisdom, double accuracy, int luck, int hitPoints, int armor) {
	this->name = name;
	this->value = value;
	this->san = san;
	this->power = power;
	this->movePower = movePower;
	this->wisdom = wisdom;
	this->accuracy = accuracy;
	this->luck = luck;
	this->hitPoints = hitPoints;
	this->armor = armor;
}
//获取名称
string Item::getName()const { return name; }
//获取价格
int Item::getValue()const { return value; }
//获取理智（加成）
int Item::getSan()const { return san; }
//获取力量（加成）
int Item::getPower()const { return power; }
//获取敏捷（加成）（应用小数型有助于战斗中进行判定）
double Item::getMovePower()const { return movePower; }
//获取精确度（加成）（应用小数型有助于战斗中进行判定）
double Item::getAccuracy()const { return accuracy; }
//获取幸运（加成）
int Item::getLuck()const { return luck; }
//获取智力（加成）
int Item::getWisdom()const { return wisdom; }
//获取生命值（加成）
int Item::getHitPoints()const { return hitPoints; }
//获取护甲
int Item::getArmor()const { return armor; }
//设置名称
void Item::setName(string name) { this->name = name; }
//设置价值
void Item::setValue(int value) { this->value = value; }
//设置理智
void Item::setSan(int san) { this->san = san; }
//设置力量
void Item::setPower(int power) { this->power = power; }
//获设置敏捷
void Item::setMovePower(double movePower) { this->movePower = movePower; }
//设置智力
void Item::setWisdom(int wisdom) { this->wisdom = wisdom; }
//设置准确度
void Item::setAccuracy(double accuracy) { this->accuracy = accuracy; }
//设置幸运值
void Item::setLuck(int luck) { this->luck = luck; }
//设置生命值
void Item::setHitPoints(int hitpoints) { this->hitPoints = hitpoints; }
//设置护甲
void Item::setArmor(int armor) { this->armor = armor; }
//导入各项属性
void Item::showInfo() {
	cout << endl << "==================== 基础物品信息 ====================" << endl;
	cout << left << setw(12) << "物品名称" << setw(10) << getName() << endl;
	cout << left << setw(12) << "价值" << setw(10) << getValue() << endl;
	cout << left << setw(12) << "额外生命" << setw(10) << getHitPoints() << endl;
	cout << left << setw(12) << "护甲" << setw(10) << getArmor() << endl;
	cout << left << setw(12) << "力量加成" << setw(10) << getPower() << endl;
	cout << left << setw(12) << "敏捷加成" << setw(10) << getMovePower() << endl;
	cout << "======================================================" << endl;
}
Equipment::Equipment(const Equipment& equipment) :
	Item(equipment.getName(), equipment.getValue(), equipment.getSan(),
		equipment.getPower(), equipment.getMovePower()
		, equipment.getWisdom(), equipment.getAccuracy(), equipment.getLuck(),
		equipment.getHitPoints(), equipment.getArmor()), consume(equipment.consume) {
}
//输出武器信息
void Equipment::showInfo() {
	cout << endl << "==================== 装备信息 ====================" << endl;
	cout << left << setw(12) << "名称" <<
		left << setw(10) << "价值" <<
		left << setw(8) << "理智" <<
		left << setw(8) << "力量" <<
		left << setw(8) << "敏捷" <<
		left << setw(8) << "智力" <<
		left << setw(10) << "精准度" <<
		left << setw(8) << "幸运" <<
		left << setw(10) << "额外生命" <<
		left << setw(8) << " 护甲" <<
		left << setw(8) << "耐久" << endl;
	cout << "--------------------------------------------------" << endl;
	cout << left << setw(12) << getName() <<
		left << setw(10) << getValue() <<
		left << setw(8) << getSan() <<
		left << setw(8) << getPower() <<
		left << setw(8) << getMovePower() <<
		left << setw(8) << getWisdom() <<
		left << setw(10) << getAccuracy() <<
		left << setw(8) << getLuck() <<
		left << setw(10) << getHitPoints() <<
		left << setw(8) << getArmor() <<
		left << setw(8) << consume << endl;
	cout << "==================================================" << endl;
}
//初始化各个属性
Equipment::Equipment() :Item("", 0, 0, 0, 0, 0, 0, 0, 0, 0), consume(0) {}
int Equipment::getConsume()const {
	return consume;
}
//装备价值赋予各个装备属性
void Equipment::initEquipment(int index, int value) {
	setName(WEAPONLIST[index]);
	this->consume = 100;
	//0：剑 1：弓箭 2：铠甲 3：盾牌 4; 鞋子 5：头盔 6：护腿
	switch (index)
	{
		//剑
	case 0:
		setPower(getPower() + value * 1.0);
		break;
		//弓箭
	case 1:
		setPower(getPower() + value * 1.0);
		setAccuracy(getAccuracy() + value * 0.2);
		break;
		//铠甲
	case 2:
		setHitPoints(getHitPoints() + value * 1.0);
		setArmor(getArmor() + value * 0.8);
		break;
		//盾牌
	case 3:
		setMovePower(getMovePower() - value * 0.2);
		setArmor(getArmor() + value * 1.0);
		break;
		//鞋子
	case 4:
		setMovePower(getMovePower() + value * 0.4);
		setArmor(getArmor() + value * 0.4);
		break;
		//头盔
	case 5:
		setArmor(getArmor() + value * 0.2);
		setWisdom(getWisdom() + value * 1.0);
		setSan(getSan() + value * 1.0);
		break;
		//护腿
	case 6:
		setArmor(getArmor() + value * 0.6);
		break;
		//错误
	default:
		break;
	}
}

string Equipment::slotToString(EquipSlot slot)  {
	switch (slot) {
	case EquipSlot::Weapon: return "武器";
	case EquipSlot::Head: return "头部";
	case EquipSlot::Torso: return "躯干";
	case EquipSlot::Foot: return "脚部";
	case EquipSlot::Legs: return "腿部";
	case EquipSlot::Deputy: return "副手";
	case EquipSlot::Accessory: return "饰品";
	default: return "未知";
	}
}
void Equipment::showEquippedItems() {
	cout << endl << "==================== 已装备物品 ====================" << endl;
	if (equippedItems.empty()) {
		cout << "当前没有装备任何物品" << endl;
		return;
	}

	cout << left << setw(15) << "装备名称" << setw(12) << "装备槽位" << setw(10) << "耐久度" << endl;
	cout << "------------------------------------------------------" << endl;

	for (const auto& pair : equippedItems) {
		EquipSlot slot = pair.first;
		Equipment* equip = pair.second;
		cout << left << setw(15) << equip->getName()
			<< setw(12) << slotToString(slot)
			<< setw(10) << equip->getConsume() << endl;
	}
	cout << "======================================================" << endl;
}
void Equipment::setSlot(EquipSlot slot) {
	this->slot = slot;
}
EquipSlot Equipment::getSlot()const {
	return slot;
}
bool Equipment::hasEquipment(EquipSlot slot) {
	return equippedItems.find(slot) != equippedItems.end();
}
Equipment* Equipment::unEquipPart(EquipSlot slot) {
	if (!hasEquipment(slot)) {
		cout << slotToString(slot) << "槽没有装备" << endl;
		return nullptr;
	}
	Equipment* equip = equippedItems[slot];
	equippedItems.erase(slot);
	cout << "卸下了" << equip->getName() << endl;
	return equip;
}
//设置药水的初始属性
Drug::Drug(string name, int value, char type, int resilience) :
	Item(name, value, 0, 0, 0, 0, 0, 0, 0, 0) {
	this->type = type;
	this->resilience = resilience;
}
//打印药水属性
void Drug::showInfo() {
	string TYPE;
	switch (type)//种类 H：生命，M:魔力，S：理智
	{
	case'H':
		TYPE = "生命";
		break;
	case'M':
		TYPE = "魔力";
		break;
	case'S':
		TYPE = "理智";
		break;
	default:
		TYPE = "未知";
		break;
	}
	cout << endl << "==================== 药水信息 ====================" << endl;
	cout << left << setw(12) << "名称" <<
		left << setw(12) << "价值" <<
		left << setw(12) << "类型" <<
		left << setw(12) << "恢复力" << endl <<
		"--------------------------------------------------" << endl <<
		left << setw(12) << getName() <<
		left << setw(12) << getValue() <<
		left << setw(12) << getType() <<
		left << setw(12) << getResilience() << endl
		<< "==================================================" << endl;
}
//获取药水种类
char Drug::getType()const { return type; }
//获取药水恢复力
int Drug::getResilience()const { return resilience; }

//获取特殊物品用途
string Special::getPurpose()const { return purpose; }
//特殊物品是否为一次性消耗品
bool Special::getIsConsumable()const { return isConsumable; }
//（物品是否被使用）跟踪状态
bool Special::getIsUsed()const { return isUsed; }
//复制函数
Special::Special(const Special& special) :
	Item(special.getName(), 0, 0, 0, 0, 0, 0, 0, 0, 0),
	purpose(special.getPurpose()),
	isConsumable(special.getIsConsumable()),
	isUsed(false) {
}
//使用物品
bool Special::use() {
	if (getName().empty()) {
		cout << "未知物品" << endl;
		return false;
	}
	if (isConsumable && isUsed) {
		cout << getName() << "已经被使用过了！" << endl;
		return false;
	}
	cout << "使用了" << getName() << ":" << getPurpose();
	if (isConsumable) {
		cout << "(该物品已被消耗 )" << endl;
		isUsed = true;
	}
	else {
		cout << "(可重复利用)" << endl;
	}
	return true;
}
//重置物品状态
void Special::reSet() {
	if (!isConsumable) {
		isUsed = false;
		cout << getName() << "可以再次使用" << endl;
	}
	else {
		cout << getName() << "无法再次使用" << endl;
	}
}
//书写物品信息
void Special::showInfo() {
	cout << endl << "==================== 物品信息 ====================" << endl;
	cout << left << setw(15) << "物品名称" <<
		left << setw(20) << "用途" <<
		left << setw(15) << "是否可消耗" <<
		left << setw(15) << "当前状态" << endl <<
		"------------------------------------------------------" << endl <<
		left << setw(15) << getName() <<
		left << setw(20) << purpose <<
		left << setw(15) << (isConsumable ? "是" : "否") <<
		left << setw(15) << (isUsed ? "已使用" : "未使用") << endl <<
		"======================================================" << endl;
}
